local skill = fk.CreateSkill {
  name = "ling__dismantlement_skill",
}

skill:addEffect("cardskill", {
  prompt = "#ling__dismantlement_skill",
  target_num = 1,
  mod_target_filter = function(self, player, to_select, selected, card)
    return to_select ~= player and not to_select:isAllNude()
  end,
  target_filter = Util.CardTargetFilter,
  on_effect = function(self, room, effect)
    local from = effect.from
    local to = effect.to
    if from.dead or to.dead or to:isNude() then return end
    local flag = "hej"
    if from:distanceTo(to) == 1 then
      local card_data = {}
      if not to:isKongcheng() then
        table.insert(card_data, { "$Hand", to:getCardIds("h") })
      end
      if #to:getCardIds("e") > 0 then
        table.insert(card_data, { "$Equip", to:getCardIds("e") })
      end
      if #to:getCardIds("j") > 0 then
        table.insert(card_data, { "$Judge", to:getCardIds("j") })
      end
      flag = { card_data = card_data }
    end
    local cid = room:askToChooseCard(from, {
      target = to,
      flag = flag,
      skill_name = skill.name,
    })
    room:throwCard(cid, skill.name, to, from)
  end,
})

skill:addAI(nil, "__card_skill")
skill:addAI(nil, "default_card_skill")

return skill
